package com.zzc;

import com.zzc.bean.Employee;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import java.util.Map;

public class LoginFilter extends AbstractInterceptor {
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        System.out.println("开始拦截");
        //获取ActionContext
        ActionContext ac = actionInvocation.getInvocationContext();
        //获取session
        Map<String, Object> session = ac.getSession();
        //获取session中的用户信息
        Employee employee = (Employee) session.get("employee");
        //判断用户信息是否正确
        if (employee == null) {
            System.out.println("struts 未登录拦截");
            return "login";
        } else {
            System.out.println("struts 已登录 不拦截");
            return actionInvocation.invoke();
        }
    }
}